<#include "../global/header.html">
    <div class="aw-container-wrap">
        <div class="aw-container aw-wecenter">
            <div class="container aw-user-sort">
                <div class="row">
                    <div class="col-sm-12 col-md-12 aw-user-sort-title">
                        <!--<h3 class="pull-left">用户设置</h3>-->
                        <ul class="nav nav-tabs aw-reset-nav-tabs pull-right" id="tab">
                            <#if page==2>
                                <li class="active">
                                    <#else>
                                        <li>
                            </#if>

                            <a href="/news/condition">匹配条件</a></li>

                            <#if page==0>
                                <li class="active">

                                    <#else>
                                        <li>
                            </#if>
                            <a href="/news/_old/">过期招标信息</a></li>

                            <#if page==1>
                                <li class="active">
                                    <#else>
                                        <li>
                            </#if>
                            <a href="/news/_new">最新招标信息</a></li>

                        </ul>
                    </div>
                </div>

                <div class="row active">
                    <div class="col-sm-12 col-md-3 side-nav clearfix">
                        <!--<ul>-->
                            <!--<li>-->
                                <!--<a href="">xxx12231</a>-->
                            <!--</li>-->
                        <!--</ul>-->
                    </div>
                    <div class="col-sm-12 col-md-9 content">
                        <div class="aw-mod">
                            <div class="aw-mod-body">
                            <div style="height:20px;"></div>

                            <div class="aw-container-wrap">
                            <div class="aw-container aw-wecenter aw-user">
                            <div class="aw-user-setting">
                            <div class="tab-content clearfix">

                            <!-- 关键字 -->
                            <div class="aw-mod">
                                <ul class="breadcrumb">
                                    <li>关键字</li>
                                </ul>
                                <div class="aw-mod-body aw-user-educate aw-user-setting-layout aw-user-setting-reset-table text-center">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <th width="20%" class="text-center">编号</th>
                                            <th class="text-center">关键字</th>

                                            <th width="20%" class="text-center">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <#list keyword_list as x>
                                            <tr>
                                                <td>
                                                    ${x_index+1}
                                                </td>
                                                <td>
                                                    ${x.keyword}
                                                </td>
                                                <td>
                                                    <a href="keyword/delete/${x.id}">删除</a>
                                                </td>

                                            </tr>
                                        </#list>
                                        <tr>
                                            <td></td>
                                            <td>
                                                <input type="text" style="width:450px;margin-left: 50px" class="school form-control" placeholder="多个关键字可以以空格分隔" id="add-key">
                                            </td>
                                            <td>
                                                <a href="javascript:void(0);" onclick="add_keyword();">增加</a>
                                            </td>
                                        <tr>
                                            <td colspan="3">最多只能设置五个关键字，关键字不能为词组，只能为单个的词，如：机械，计算机...等。</td>
                                        </tr>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <!-- end 关键字 -->

                            <!-- 区域设置 -->
                            <div class="aw-mod">
                                <!--<div class="aw-mod-head">-->
                                <!--<h4>区域设置</h4>-->
                                <!--</div>-->
                                <ul class="breadcrumb">
                                    <li>区域设置</li>
                                </ul>
                                <div class="aw-mod-body aw-user-work aw-user-setting-layout aw-user-setting-reset-table text-center">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <th width="20%" class="text-center">编号</th>
                                            <th class="text-center">关注区域</th>
                                            <th width="15%" class="text-center">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <#list user_distruct_list! as x1>
                                            <tr>
                                                <td>
                                                    ${x1_index+1!}
                                                </td>
                                                <td>
                                                    ${x1.name_d!}
                                                </td>
                                                <td>
                                                    <!--<a href="user_district/delete/${x1.id}">取消关注</a>-->
                                                    <a href="javascript:;"  onclick="delsel();">取消关注</a>
                                                </td>

                                            </tr>
                                        </#list>
                                        <tr>
                                            <td></td>
                                            <td>
                                                <input type="hidden" value="123" id="hiden1">
                                                <select  id="select" style="width: 120px" onchange="sel();">
                                                    <option value="0">
                                                        --请选择省份--
                                                    </option>
                                                    <#list district_list! as a>
                                                        <option value="${a.code}">
                                                            ${a.name}
                                                        </option>
                                                    </#list>
                                                </select>
                                                <div class="modal" style="margin-left: 150px;margin-top: 80px"  id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                                    <div class="modal-dialog">
                                                        <div class="modal-content"  style="width: 480px">
                                                            <div class="modal-header" id="msgdiv">
                                                                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                                                <h4 class="modal-title" id="myModalLabel"></h4>
                                                                <h5 id="tishi" style="font-weight:bolder">注意：当不选择城市提交时，可以直接关注该省！</h5>
                                                            </div>

                                                            <div class="modal-body" >
                                                                <ul class="hy-list" id="select1" style="height:300px;overflow-y:scroll;">


                                                                </ul>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                                                <button type="button" id="but" class="btn btn-primary" onclick="add_distruct();">提交</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                            </td>
                                            <td>
                                                <a href="javascript:;" onclick="delsel();">修改</a>
                                            </td>
                                        <tr>
                                            <td colspan="3">只能关注五个区域。如需关注其他区域，请先取消已经关注的区域。</td>
                                        </tr>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <!-- end 区域设置 -->
                            <!-- 资质设置 -->
                            <div class="aw-mod">
                                <!--<div class="aw-mod-head">-->
                                <!--<h4>资质设置</h4>-->
                                <!--</div>-->
                                <ul class="breadcrumb">
                                    <li>资质设置</li>
                                </ul>

                                <div class="aw-mod-body aw-user-work aw-user-setting-layout aw-user-setting-reset-table text-center">
                                    <table class="table table-bordered" >
                                        <thead>
                                        <tr>
                                            <th width="20%" class="text-center">编号</th>
                                            <th class="text-center" >关注资质</th>

                                            <th width="15%" class="text-center">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <#list qualificationList as x1>
                                            <tr>
                                                <td>
                                                    ${x1_index+1}
                                                </td>
                                                <td>
                                                    ${x1.name}
                                                    <#if x1.is_ok==0>
                                                        [<span class="highlight hot">未审核</span>]
                                                    </#if>
                                                </td>
                                                <td>
                                                    <a href="user_qualification/delete/${x1.id}">取消关注</a>
                                                </td>

                                            </tr>
                                        </#list>
                                        <tr>
                                            <td></td>
                                            <td>
                                                <div class="inline" style="margin-top: 8px">
                                                    <div class="form-group" style="float: left;margin-left: 160px" >

                                                        <input type="text" class="form-control"  style="width: 150px" placeholder="如:城乡规划" id="add_qu">
                                                    </div>
                                                    <div class="form-group" style="float: left">
                                                        或<select  id="select_qu" style="width: 120px;margin-top: 6px">
                                                        <option value="0">
                                                            --请选择资质--
                                                        </option>
                                                        <#list unQualificationList as a>
                                                            <option value="${a.id}" style="width: 100px">
                                                                ${a.name}
                                                                <#if a.is_ok==0>
                                                                    [未审核]
                                                                </#if>
                                                            </option>
                                                        </#list>
                                                    </select></div></div>
                                            </td>
                                            <td>
                                                <a href="javascript:void(0);" onclick="add_qualification();">关注</a>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3" style="text-align: left">
                                                请在输入框中输入资质信息，或者在下拉菜单中选择资质信息，输入框中资质信息会保存在下拉菜单中。<br/>
                                                注意：<br/>
                                                1.输入时不要在文本中输入空格等特殊符号。<br/>
                                                2.未审核的资质关注后无效。
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <!-- end 资质设置 -->
                            </div>
                            </div>
                            </div>
                            </div>


                                </div>
                            </div>
                        </div>
                    </div>


                </div>
            </div>
        </div>


    <style type="text/css">
        .dis{display: none}
    </style>

    <script type="text/javascript" >

    function delsel(){
        $("#h5").remove();
        $("#select1").html("");
        $.post(
                "user_district/findUserdis",
                function(data){
                    $("#myModalLabel").text("请点击您不需要关注的地区");
                    var se = data.list;
                    if(se.length!=0) {
                        for (var i = 1; i <= se.length; i++) {
                            $("#select1").append("<li class='col-md-6' style='text-align: left'><label><input style='width: 20px' checked type='checkbox' name='select1' value='" + se[i - 1].district_id + "' >" + se[i - 1].name_d + "</label></li>");
                            $("#hiden1").val(0);
                            $("#but").prop("disabled", false);
                            $("#tishi").addClass("dis");
                            $('#myModal').modal('show')
                        }
                    }else{
                        $("#myModalLabel").text("请点击您不需要关注的地区");
                        alert("您当前没有选择城市，请选择城市后在进行修改！");
                    }
                },"json"
        );
    }
    //    function sel(){
    //        var val=$("#select").val();
    //        $.post(
    //                "/home/sel",
    //                {id:val},
    //                function(data){
    //                   if(data.msg==0){
    //                       $("#select1").html("");
    //                   }
    //                },"json"
    //        );
    //    }

    function sel(){
        $("#h5").remove();
        $("#select1").html("");
        var val=$("#select").val();
        if(val==0){
            $("#select1").append("请选择省份！");
            $("#but").prop("disabled", true);
            $('#myModal').modal('show')
            return;
        }else {
            $.post(
                    "/home/selectChange",
                    {id: val},
                    function (data) {

                        var se = data.list1;
//                      document.getElementById("select1").options[0] = new Option(" --请选择地区--",0);
//
                        if(se.length!=0) {

                            for (var i = 1; i <= se.length; i++) {
//                        document.getElementById("select1").options[i] = new Option(se[i-1].name,se[i-1].id);
                                $("#select1").append("<li class='col-md-6' style='text-align: left'><label><input style='width: 20px' type='checkbox' name='select1' value='" +se[i - 1].code + "' >" + se[i - 1].name + "</label></li>");
                            }
                            $("#myModalLabel").text("请选择地区");
                            $("#hiden1").val(1);
                            $("#but").prop("disabled", false);
                            $("#tishi").removeClass("dis");
                            $('#myModal').modal('show')
                        }else{
                            $("#myModalLabel").text("请选择地区");
                            $("#select1").html("");
                            $("#select1").append("该城市没有下级城市，可直接提交!");
                            $("#hiden1").val(1);
                            $("#but").prop("disabled", false);
                            $("#tishi").addClass("dis");
                            $('#myModal').modal('show')

                        }
                    }, "json"
            );
        }
    }
    function add_keyword(){
        //遍历data
        var key = $("#add-key").val().trim();
        if(key==''){
            alert('添加失败，原因：关键字不能为空');
        }else if(key.length>30){
            alert('添加失败，原因：关键字长度过长');
        }else{
            $.post("keyword/add",{key:key},function(data){
                if (data!=null) {
                    data=data.msg;
                    if(data==1){
                        alert('添加成功');
                        myrefresh();
                    }else if(data==0){
                        alert('添加失败，原因：数据重复！');
                    }else if(data==2){
                        alert('添加失败，原因：设置关键字最多为五个！');
                    }else if(data==3){
                        alert('添加失败，原因：输入为空字符串！');
                    }else{
                        alert('添加失败，原因：未知错误！');
                    }
                }else{
                    alert('未知错误！');
                }
            },"json");
        }
    }
    function add_distruct() {
        $("#h5").remove();
        var hiden=$("#hiden1").val();
        var key1="";
        var temp = document.getElementsByName("select1");
        for(var i=0;i<temp.length;i++){
            if(temp[i].checked) {
                if (key1 =="") {
                    key1 += temp[i].value;
                } else {
                    key1 += "," + temp[i].value;
                }
            }

        }
        //遍历data
        var key = $("#select").val();

        if(key1.length==0 && hiden==1){
            $.post("user_district/add", {
                key : key,key1:key1
            }, function(data) {
                if (data != null) {
                    listSize=data.listSize;
                    data = data.msg;
                    if (data == 1) {
                        alert('添加成功');
                        myrefresh();
                    } else if (data == 0) {
                        alert('添加失败，原因：数据重复！');
                    }else if (data == 2) {
                        $("#msgdiv").append("<h5 id='h5' style='color: red'>最多关注区域为5个！您已经添加了"+listSize+"个，还可以添加"+(5-listSize)+"个！</h5>");
//                            alert('最多关注区域为五个！已经添加了'+listSize+'个，还可以添加'+(5-listSize)+'个！');
                    } else {
                        alert('添加失败，原因：未知错误！');
                    }
                } else {
                    alert('未知错误！');
                }
            }, "json");
        }else if(hiden==0){
            $.post("user_district/add", {
                        key : -1,key1:key1
                    }, function(data) {
                        if (data != null) {
                            listSize=data.listSize;
                            data = data.msg;

                            if (data == 1) {
                                alert('修改成功');
                                $("#hiden").val(1);
                                myrefresh();
                            } else if (data == 0) {
                                alert('添加失败，原因：数据重复！');
                            }else if (data == 2) {
                                $("#msgdiv").append("<h5 id='h5' style='color: red'>最多关注区域为5个！您已经添加了"+listSize+"个，还可以添加"+(5-listSize)+"个！</h5>");
//                                    alert('最多关注区域为五个！已经添加了'+listSize+'个，还可以添加'+(5-listSize)+'个！');
                            } else {
                                alert('添加失败，原因：未知错误！');
                            }
                        } else {
                            alert('未知错误！');
                        }
                    }
                    ,"json"
            );
        }
        else{
            $.post("user_district/add", {
                key : key,key1:key1
            }, function(data) {
                if (data != null) {
                    listSize=data.listSize;
                    data = data.msg;
                    if (data == 1) {
                        alert('添加成功');
                        myrefresh();
                    } else if (data == 0) {
                        alert('添加失败，原因：数据重复！');
                    }else if (data == 2) {
//                            $("#ds").re
                        $("#msgdiv").append("<h5 id='h5' style='color: red'>最多关注区域为5个！您已经添加了"+listSize+"个，还可以添加"+(5-listSize)+"个！</h5>");
//                            alert('最多关注区域为五个！您已经添加了'+listSize+'个，还可以添加'+(5-listSize)+'个！');
                    } else {
                        alert('添加失败，原因：未知错误！');
                    }
                } else {
                    alert('未知错误！');
                }
            }, "json");
        }

//        }
    }
    function add_qualification() {
        //遍历data
        var num;
        var key = $("#select_qu").val();
        if (key == 0) {
            key =  $("#add_qu").val().trim();
            if(key=='') {
                alert('请选择或者输入需要关注的资质');
            }else if(key.length>20){
                alert('添加失败，原因：资质信息过长！');
            }else{
                //输入资质
                add_qu(key,0);
            }

        } else {
            //选择资质
            add_qu(key,1);
        }
    }

    function add_qu(key,num){
        $.post("user_qualification/add", {
            qualificationId : key,quNum:num
        }, function(data) {
            if (data != null) {
                data = data.msg;
                if (data == 1) {
                    alert('添加成功');
                    myrefresh();
                } else if (data == 0) {
                    alert('添加失败，原因：数据重复！');
                }else if (data == 2) {
                    alert('添加失败，原因：超过资质设置上限！');
                } else if(data ==3) {
                    alert('添加失败，原因输入资质为空');
                }else if(data ==5){
                    alert('自定义资质未审核！');
                    myrefresh();
                }else
                {
                    alert('添加失败，原因：未知错误！');
                }
            } else {
                alert('未知错误！');
            }
        }, "json");
    }

    function myrefresh()
    {
        window.location.reload();
    }
    </script>

    <#include "../global/footer.html">